# -*- coding: utf-8 -*-
import feedparser
import news
import re
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class UpdateFeedThread(QThread):
	def __init__(self,mainUi,urlFeed):
			QThread.__init__(self)
			self.urlFeed = urlFeed
			self.mainUi = mainUi
			self.SEEP_TIME = 600

	def run(self):
		self.readFeed(self.urlFeed)
		while True:
			# self.feed = feedparser.parse(self.urlFeed, modified=self.lastUpdate)
			self.feed = feedparser.parse(self.urlFeed)
			self.feed = {} #provisorio hasta resolver el tema de cuando hay feeds nuevos.
			if (self.feed.feed == {}):
				print "Actualizado"
				self.sleep(self.SEEP_TIME)
			else:
				for n in self.feed.entries:
					print n

	def readFeed(self,urlFeed):
		self.feed = feedparser.parse(urlFeed)
		# self.lastUpdate = self.feed.modified
		for n in self.feed.entries:
			#print n.link
			#print n.updated
			self.emit(SIGNAL("asignal(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),n.title, n.updated,self.remove_html_tags(n.summary),n.link)

	def remove_html_tags(self,data):
		p = re.compile(r'<.*?>')
		return p.sub('', data)
